#include <iostream>
#include <string>
#include "httplib.h"

void hi(const httplib::Request& req, httplib::Response& res)
{
    res.status = 200;
    res.set_content("Hello World!", "text/plain");
}

void hello(const httplib::Request& req, httplib::Response& res)
{
    auto number = req.matches[1];
    res.status = 200;
    res.set_content(number, "text/plain");
}
void multipart(const httplib::Request req, httplib::Response res){
    const auto exist = req.has_file("file");
    if(exist == false){
        std::cout<< "file not exist" << std::endl;
        res.status = 404;
        return;
    }
    res.status = 200;
    const auto file = req.get_file_value("file");
    std::cout << "file.name : " << file.name << std::endl;
    std::cout << "file.filename : " << file.filename << std::endl;
    std::cout << "file.content : " << file.content << std::endl;
    std::cout << "file.content_type : " << file.content_type << std::endl;

}

int main()
{
    httplib::Server ser;
    ser.Get("/Hi",hi);
    ser.Get(R"(/hello/(\d+))", hello);
    ser.Post("/upload",multipart);

    ser.listen("0.0.0.0", 9090);
    return 0;
}